package com.sdp.wx.db.wx_wz_output_detail.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.wx.db.wx_wz_output_detail.entity.WxWzOutputDetail;
import com.sdp.wx.db.wx_wz_output_detail.mapper.WxWzOutputDetailMapper;
import com.sdp.wx.db.wx_wz_output_detail.service.IWxWzOutputDetailService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-01-30
 */
@Service
public class WxWzOutputDetailServiceImpl extends ServiceImpl<WxWzOutputDetailMapper, WxWzOutputDetail> implements IWxWzOutputDetailService {

	@Override
	public int queryWzOutputDetailCountByRepairCode(String repairCode) {
		LambdaQueryWrapper<WxWzOutputDetail> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxWzOutputDetail::getRepairCode, repairCode);
		return count(queryWrapper);
	}

	@Override
	public BigDecimal queryWzAmountByRepairCode(String repairCode) {
		LambdaQueryWrapper<WxWzOutputDetail> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxWzOutputDetail::getRepairCode, repairCode);
		List<WxWzOutputDetail> list = list(queryWrapper);
		if(list==null || list.size()==0) {
			return BigDecimal.ZERO;
		}
		
		BigDecimal wzAmount = BigDecimal.ZERO;
		for(WxWzOutputDetail opd : list) {
			wzAmount = wzAmount.add(opd.getArmyPrice().multiply(opd.getOutputNum()));
		}
		return wzAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
	}

	@Override
	public List<WxWzOutputDetail> queryWzOutputDetailByRepairCode(String repairCode) {
		LambdaQueryWrapper<WxWzOutputDetail> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxWzOutputDetail::getRepairCode, repairCode);
		return list(queryWrapper);
	}

	

}
